#include<iostream>
#include<vector>
#include<algorithm> // Include this header for std::sort
using namespace std;

class Solution {
public:
   int numberOfPairs(vector<vector<int>>& points) {
       // Replace ranges::sort with std::sort
       std::sort(points.begin(), points.end(), [](const vector<int>& p1, const vector<int>& p2) {
           return make_pair(p1[0], -p1[1]) < make_pair(p2[0], -p2[1]);
       });
       int ans = 0, n = points.size();
       for (int i = 0; i < n; i++) {
           int y1 = points[i][1];
           int max_y = INT_MIN;
           for (int j = i + 1; j < n && max_y < y1; j++) {
               int y2 = points[j][1];
               if (y2 <= y1 && y2 > max_y) {
                   max_y = y2;
                   ans++;
               }
           }
       }
       return ans;
   }
};